package com.qf.common.swagger;

import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import javax.annotation.Resource;

/**
 * @author chengqiang
 * @Create 2024-01-11-9:31
 * @Description:
 */
@Configuration
@EnableOpenApi
// @Import(SwaggerProperties.class)
// @ComponentScan("com.qf.common.swagger")
public class SwaggerConfig {

    @Resource
    private SwaggerProperties swaggerProperties;
    // @Autowired
    // private Config config;
    // public static void main(String[] args) {
    //     System.out.println(new SwaggerConfig().getSwaggerProperties().getName());
    // }
    @Bean
    public Docket docket(ApiInfo apiInfo){
        return new Docket(DocumentationType.OAS_30).apiInfo(apiInfo).enable(swaggerProperties.getEnable())
                .groupName(swaggerProperties.getGroupName())
                .select()
                .apis(RequestHandlerSelectors.basePackage(swaggerProperties.getBasePackage()))
                .paths(PathSelectors.any())
                .build();
    }


    @Bean
    public ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title(swaggerProperties.getTitle())
                .description(swaggerProperties.getDescription())
                .version(swaggerProperties.getVersion())
                .contact(new Contact(swaggerProperties.getName(),swaggerProperties.getUrl(),swaggerProperties.getEmail()))
                .build();
    }

}
